﻿package com.pandemicode.framework.smtp.collections {
	import com.pandemicode.framework.smtp.mailer.EmailAttachment;
	import com.pandemicode.framework.smtp.mailer.parts.Boundary;
	import com.pandemicode.framework.smtp.mailer.Mailer;
	
	/**
	* @author Mike Lawrence
	*/
	public class EmailAttachmentCollection extends Array {
		public function EmailAttachmentCollection() {}
		
		public function add(emailAttachment:EmailAttachment):uint {
			return this.push(emailAttachment);
		}
		
		public function get(index:int):EmailAttachment {
			return this[index] as EmailAttachment;
		}
		
		public function remove(emailAttachment:EmailAttachment):Boolean {
			for (var i:int = 0; i < this.length; i++) {
				var add:EmailAttachment = this[i] as EmailAttachment;
				if (add == emailAttachment) {
					this.splice(i, 1);
					return true;
				}
			}
			return false;
		}
		
		public function removeAt(index:int):Boolean {
			if (index > this.length - 1)
				return false;
				
			this.splice(index, 1);
			return true;
		}
		
		public function format(boundary:Boundary):String {
			var s:String = "";
			for each(var attachment:EmailAttachment in this) {
				s += boundary.valueDashed;
				s += attachment.toString();
				s += Mailer.NEWLINE;
			}
			return s;
		}
	}
}
